<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>新增员工</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 引入 Bootstrap -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/js/jquery-3.5.1.js"></script>
</head>
<body>
<div class="container">

    <div class="row clearfix">
        <div class="col-md-6 column">
            <div class="page-header">
                <h1>
                    <small>新增员工</small>
                </h1>
            </div>
        </div>
    </div>
    <form action="${pageContext.request.contextPath}/employee/save" method="post">
        <div class="form-group col-md-6 column">
            <label>员工名</label>
            <input type="text" id="empName" name="empName" class="form-control" required>
        </div>
        <div class="form-group col-md-6 column">
            <label>部门号</label>
            <select id="dept" name="deptId" class="form-control" style="margin-right: 50px;" onclick="getDept()">
                <option >==请选择==</option>
            </select>
        </div>
        <div class="form-group col-md-6 column">
            <label>职务</label>
            <input type="text" id="jobName" name="jobName" class="form-control" required>
        </div>
        <div class="form-group col-md-6 column">
            <label>入职时间</label>
            <input type="date" id="joinDate" name="joinDate" class="form-control" required>
        </div>
        <div class="form-group col-md-6 column">
            <label>联系方式</label>
            <input type="text" id="telephone" name="telephone" class="form-control" required>
        </div>
        <div class="form-group">
            <button id="save" class="form-control btn-success">添加</button>
        </div>

    </form>

</div>
</body>

<script>
    function getDept() {
        let url = "${pageContext.request.contextPath}/dept/findAll"
        $("#dept").html("<option>==请选择==</option>");
        $.ajax({
            url:url,
            type:"post",
            success:function (resp) {
                console.log(resp)
                if (resp!=null){
                    for (var i = 0;i<resp.length;i++){
                        $("#dept").append("<option name='"+resp[i].deptId+"' value='"+resp[i].deptId+"'>"+[resp[i].deptId]+'------>>'+resp[i].deptName+"</option>");
                    }
                }
            }

        })

    }

</script>
</html>
